let Server_url = "http://26031mg941.qicp.vip:14293"
module.exports = {//抛出
  get: (option) => {//get请求封装
    return new Promise((resolve, reject) => {
      wx.request({
        url: Server_url + option.url,
        data: option.data,
        method: 'GET',
        // header: { "Content-Type": "application/x-www-form-urlencoded"},//按需求改变
        success(res) {
          resolve(res);//请求成功 通过resolve(res);抛出正常
        },
        fail(res) {
          reject(res);//请求失败 通过resolve(res);抛出异常
        }
      })
    })
  },
  post: (option) => {//get请求封装
    return new Promise((resolve, reject) => {
      console.log(typeof (option.data))
      console.log(option.data)
      // var thisData = JSON.toJSONString(option.data)
      wx.request({
        url: Server_url + option.url,
        data: option.data,
        method: 'POST',
        timeout: 40000,
        header: { "Content-Type": "application/x-www-form-urlencoded" },
        success(res) {
          resolve(res);//请求成功 将res返回做下一步处理
        },
        fail(res) {
          // console.log(res)
          reject(res);
          if(res.errMsg == 'request:fail timeout' || res.code == -9999){
            console.log('超时')
            wx.showModal({
              title: '连接超时',
              content: '请检查网络连接',
              showCancel: false,
              success(res) {
                if (res.confirm) {
                  wx.reLaunch({
                    url: getApp().globalData.path
                  })
                }
              }
            })
          }
        }
      })
    })
  },
}
